﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using KCMS.Areas.Admin.Interfaces;

namespace KCMS.Areas.Admin.Engine
{
    public class ImageUploader : IImageUploader
    {
        public ImageUploader(IPathGenerator pathGenerator) : base(pathGenerator) { }
        public override string Save(System.Web.Helpers.WebImage image, bool thumb = false)
        {
            if (image != null)
            {
                String path = base._pathGenerator.generatePath(image, thumb);
                image.Save(base.Directory+path);
                return path;
            }
            else return null;
        }

        public override void Delete(string effectifePath)
        {
            if (effectifePath != null)
            {
                System.IO.File.Delete(base.Directory + effectifePath);
            }
        }

        public override string Update(System.Web.Helpers.WebImage newImage, string lastImagePath, bool thumb = false)
        {
            Delete(lastImagePath);
            return Save(newImage, thumb);
        }
    }
}